package com.mjk.manager.magicapi.plugin.es;

import com.mjk.manager.magicapi.core.core.annotation.MagicModule;
import org.elasticsearch.client.RestClient;
import org.ssssssss.script.annotation.Comment;

@MagicModule("es")
public class ElasticSearchModule {
    private static final String DOC = "_doc";

    private final RestClient restClient;

    public ElasticSearchModule(RestClient restClient) {
        this.restClient = restClient;
    }

    @Comment(value = "ElasticSearch REST API")
    public ElasticSearchConnection rest(String url) {
        return new ElasticSearchConnection(this.restClient, url);
    }

    public ElasticSearchIndex index(String indexName) {
        return new ElasticSearchIndex(this.restClient, indexName, DOC);
    }
}
